// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: fengyang

#pragma once

#include <map>
#include <memory>
#include <regex>
#include <string>
#include <vector>

// internal
#include "coin2/exchange/base/feed/processor.h"
#include "coin2/exchange/base/market/enums.h"

namespace coin2::exchange::bybit_futures::feed_v2 {
namespace impl {
using namespace coin2::exchange::base::symbology;
class BybitFeedProcessor : public base::feed::FeedParsingProcessor {
 public:
  explicit BybitFeedProcessor(const std::string& system_name,
                              const coin2::exchange::di::ConstantInjection& ci,
                              const feed::RawParserConfig& config,
                              const MarketExchangeApi& mea)
    : FeedParsingProcessor(
          system_name,
          mea,
          ci, config,
          "cc/coin2/exchange/bybit_futures/feed_v2/schema.json") {
  }

  void OnTopicRecord(const base::executor::TopicRecordPacket& packet) override;
};

struct BybitChannel {
  std::string type;
  std::string symbol;

  static BybitChannel Parse(const std::string& ch) {
    /*
    "orderBook25.BTCUSD"
    "orderBook_200.100ms.BTCUSD"
    "trade.BTCUSD"
    "instrument_info.100ms"
    */
    std::vector<std::string> splitted;
    splitted = Split(ch, ".");
    CHECK_GE_THROW(splitted.size(), 2) << "unknown channel: " << ch;
    return BybitChannel{splitted.front(), splitted.back()};
  }
};
}  // namespace impl
using impl::BybitFeedProcessor;
using impl::BybitChannel;
}  // namespace coin2::exchange::bybit_futures::feed_v2
